import { Lunar, Solar } from "lunar-javascript";
import { YueJiang } from "./yuejiang";
let yueJiangs = [];
let dengMing = new YueJiang(0, "登明", "亥");
let heKui = new YueJiang(1, "河魁", "戌");
let congKui = new YueJiang(2, "丛魁", "酉");
let chuanSong = new YueJiang(3, "传送", "申");
let xiaoJi = new YueJiang(4, "小吉", "未");
let shengGuang = new YueJiang(5, "胜光", "午");
let taiYi = new YueJiang(6, "太乙", "巳");
let tianGang = new YueJiang(7, "天罡", "辰");
let taiChong = new YueJiang(8, "太冲", "卯");
let gongCao = new YueJiang(9, "功曹", "寅");
let daJi = new YueJiang(10, "大吉", "丑");
let shenHou = new YueJiang(11, "神后", "子");
const columnsYuejiang = [
  { text: "登明亥将", value: "亥" },
  { text: "河魁戌将", value: "戌" },
  { text: "从魁酉将", value: "酉" },
  { text: "传送申将", value: "申" },
  { text: "小吉未将", value: "未" },
  { text: "胜光午将", value: "午" },
  { text: "太乙巳将", value: "巳" },
  { text: "天罡辰将", value: "辰" },
  { text: "太冲卯将", value: "卯" },
  { text: "功曹寅将", value: "寅" },
  { text: "大吉丑将", value: "丑" },
  { text: "神后子将", value: "子" },
];
const columnsHour = [
  { text: "子时", value: "子" },
  { text: "丑时", value: "丑" },
  { text: "寅时", value: "寅" },
  { text: "卯时", value: "卯" },
  { text: "辰时", value: "辰" },
  { text: "巳时", value: "巳" },
  { text: "午时", value: "午" },
  { text: "未时", value: "未" },
  { text: "申时", value: "申" },
  { text: "酉时", value: "酉" },
  { text: "戌时", value: "戌" },
  { text: "亥时", value: "亥" },
];
function formatToChineseDateTime(datetime) {
  let dateStr = Solar.fromDate(datetime).toYmdHms();
  let yingliDate = Lunar.fromDate(datetime).toString();
  // 解析输入字符串为 Date 对象
  const [datePart, timePart] = dateStr.split(" ");
  const [year, month, day] = datePart.split("-");
  const [hour, minute] = timePart.split(":");

  // 构建 Date 对象（注意：月份在 JavaScript 中从 0 开始，需减 1）
  const date = new Date(year, month - 1, day, hour, minute);

  // 提取各时间组件（注意：getMonth() 返回 0-11，需加 1）
  const formattedYear = date.getFullYear();
  const formattedMonth = date.getMonth() + 1;
  const formattedDay = date.getDate();
  const formattedHour = date.getHours();
  const formattedMinute = date.getMinutes();
  let gongYuanDate = `${formattedYear}年${formattedMonth}月${formattedDay}日${formattedHour}点${formattedMinute}分`;

  // 拼接成目标格式
  return {
    yingliDate: yingliDate,
    gongliDate: gongYuanDate,
  };
}
const formatterBirthDate = (type, option) => {
  if (type === "year") {
    option.text += "年";
  }
  if (type === "month") {
    option.text += "月";
  } if (type === "day") {
    option.text += "日";
  }
  return option;
};

export {
  columnsYuejiang, formatToChineseDateTime, formatterBirthDate,
  columnsHour
};
